package androidx.core.content.res;

import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.util.Base64;
import android.util.TypedValue;
import android.util.Xml;
import androidx.annotation.ArrayRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import com.huawei.hms.framework.network.restclient.hwhttp.route.IPRoute;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.go;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@RestrictTo({androidx.annotation.RestrictTo.d.ॱ})
public class FontResourcesParserCompat {

    public static final class a {
        private int ʼ;
        private int ˊ;
        private boolean ˋ;
        private int ˎ;
        private String ˏ;
        @NonNull
        private final String ॱ;

        public a(@NonNull String str, int i, boolean z, @Nullable String str2, int i2, int i3) {
            this.ॱ = str;
            this.ˎ = i;
            this.ˋ = z;
            this.ˏ = str2;
            this.ˊ = i2;
            this.ʼ = i3;
        }

        @NonNull
        public String ˊ() {
            return this.ॱ;
        }

        public int ॱ() {
            return this.ˎ;
        }

        public boolean ˏ() {
            return this.ˋ;
        }

        @Nullable
        public String ˋ() {
            return this.ˏ;
        }

        public int ˎ() {
            return this.ˊ;
        }

        public int ʼ() {
            return this.ʼ;
        }
    }

    public interface c {
    }

    public static final class d implements c {
        private final int ˊ;
        @NonNull
        private final go ˎ;
        private final int ˏ;

        public d(@NonNull go goVar, int i, int i2) {
            this.ˎ = goVar;
            this.ˏ = i;
            this.ˊ = i2;
        }

        @NonNull
        public go ˏ() {
            return this.ˎ;
        }

        public int ˋ() {
            return this.ˏ;
        }

        public int ˊ() {
            return this.ˊ;
        }
    }

    public static final class e implements c {
        @NonNull
        private final a[] ˎ;

        public e(@NonNull a[] aVarArr) {
            this.ˎ = aVarArr;
        }

        @NonNull
        public a[] ˊ() {
            return this.ˎ;
        }
    }

    @Nullable
    public static c ˎ(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        int next;
        do {
            next = xmlPullParser.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            return ˊ(xmlPullParser, resources);
        }
        throw new XmlPullParserException("No start tag found");
    }

    @Nullable
    private static c ˊ(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        xmlPullParser.require(2, null, "font-family");
        if (xmlPullParser.getName().equals("font-family")) {
            return ˏ(xmlPullParser, resources);
        }
        ॱ(xmlPullParser);
        return null;
    }

    @Nullable
    private static c ˏ(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        TypedArray obtainAttributes = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), o.ff.c.ˎ);
        String string = obtainAttributes.getString(o.ff.c.ॱॱ);
        String string2 = obtainAttributes.getString(o.ff.c.ʽ);
        String string3 = obtainAttributes.getString(o.ff.c.ʼ);
        int resourceId = obtainAttributes.getResourceId(o.ff.c.ʻ, 0);
        int integer = obtainAttributes.getInteger(o.ff.c.ᐝ, 1);
        int integer2 = obtainAttributes.getInteger(o.ff.c.ˊॱ, IPRoute.INTERVAL);
        obtainAttributes.recycle();
        if (string == null || string2 == null || string3 == null) {
            List arrayList = new ArrayList();
            while (xmlPullParser.next() != 3) {
                if (xmlPullParser.getEventType() == 2) {
                    if (xmlPullParser.getName().equals("font")) {
                        arrayList.add(ˋ(xmlPullParser, resources));
                    } else {
                        ॱ(xmlPullParser);
                    }
                }
            }
            if (arrayList.isEmpty()) {
                return null;
            }
            return new e((a[]) arrayList.toArray(new a[arrayList.size()]));
        }
        while (xmlPullParser.next() != 3) {
            ॱ(xmlPullParser);
        }
        return new d(new go(string, string2, string3, ˋ(resources, resourceId)), integer, integer2);
    }

    private static int ˋ(TypedArray typedArray, int i) {
        if (VERSION.SDK_INT >= 21) {
            return typedArray.getType(i);
        }
        TypedValue typedValue = new TypedValue();
        typedArray.getValue(i, typedValue);
        return typedValue.type;
    }

    public static List<List<byte[]>> ˋ(Resources resources, @ArrayRes int i) {
        if (i == 0) {
            return Collections.emptyList();
        }
        TypedArray obtainTypedArray = resources.obtainTypedArray(i);
        try {
            List<List<byte[]>> emptyList;
            if (obtainTypedArray.length() == 0) {
                emptyList = Collections.emptyList();
                return emptyList;
            }
            emptyList = new ArrayList();
            if (ˋ(obtainTypedArray, 0) == 1) {
                for (int i2 = 0; i2 < obtainTypedArray.length(); i2++) {
                    int resourceId = obtainTypedArray.getResourceId(i2, 0);
                    if (resourceId != 0) {
                        emptyList.add(ˋ(resources.getStringArray(resourceId)));
                    }
                }
            } else {
                emptyList.add(ˋ(resources.getStringArray(i)));
            }
            obtainTypedArray.recycle();
            return emptyList;
        } finally {
            obtainTypedArray.recycle();
        }
    }

    private static List<byte[]> ˋ(String[] strArr) {
        List<byte[]> arrayList = new ArrayList();
        for (String decode : strArr) {
            arrayList.add(Base64.decode(decode, 0));
        }
        return arrayList;
    }

    private static a ˋ(XmlPullParser xmlPullParser, Resources resources) throws XmlPullParserException, IOException {
        boolean z = true;
        TypedArray obtainAttributes = resources.obtainAttributes(Xml.asAttributeSet(xmlPullParser), o.ff.c.ˋॱ);
        int i = obtainAttributes.getInt(obtainAttributes.hasValue(o.ff.c.ॱˎ) ? o.ff.c.ॱˎ : o.ff.c.ͺ, 400);
        if (1 != obtainAttributes.getInt(obtainAttributes.hasValue(o.ff.c.ʻॱ) ? o.ff.c.ʻॱ : o.ff.c.ॱˊ, 0)) {
            z = false;
        }
        int i2 = obtainAttributes.hasValue(o.ff.c.ʼॱ) ? o.ff.c.ʼॱ : o.ff.c.ᐝॱ;
        String string = obtainAttributes.getString(obtainAttributes.hasValue(o.ff.c.ʽॱ) ? o.ff.c.ʽॱ : o.ff.c.ॱˋ);
        int i3 = obtainAttributes.getInt(i2, 0);
        i2 = obtainAttributes.hasValue(o.ff.c.ॱᐝ) ? o.ff.c.ॱᐝ : o.ff.c.ˏॱ;
        int resourceId = obtainAttributes.getResourceId(i2, 0);
        String string2 = obtainAttributes.getString(i2);
        obtainAttributes.recycle();
        while (xmlPullParser.next() != 3) {
            ॱ(xmlPullParser);
        }
        return new a(string2, i, z, string, i3, resourceId);
    }

    private static void ॱ(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        int i = 1;
        while (i > 0) {
            switch (xmlPullParser.next()) {
                case 2:
                    i++;
                    break;
                case 3:
                    i--;
                    break;
                default:
                    break;
            }
        }
    }
}
